import os,tempfile,shutil,commands
import pickle
import sys
import time

def doSetUntilDone(theurl,waittime=2):
    #repeat calling curl until a successfully curl call which will return "True"
    succ=False
    while not succ:
        cmdstr="curl --insecure -s \"%s\""%(theurl)
        (status,output)=commands.getstatusoutput(cmdstr)
        print "doSetUntilDone: Running command=%s, status=%d, output=%s"%(cmdstr,status,output)
        if status==0 and output=="True":
            succ=True
        else:
            time.sleep(waittime)

def doGetUntilDone(theurl,waittime=2):
    #repeat calling curl until a successfully curl call which will return "True"
    while True:
        cmdstr="curl --insecure -s \"%s\""%(theurl)
        (status,output)=commands.getstatusoutput(cmdstr)
        print "doSetUntilDone: Running command=%s, status=%d, output=%s"%(cmdstr,status,output)
        if status==0:
            return output
        time.sleep(waittime)

def doGet(theurl):
    cmdstr="curl --insecure -s \"%s\""%(theurl)
    (status,output)=commands.getstatusoutput(cmdstr)
    print "doSetUntilDone: Running command=%s, status=%d, output=%s"%(cmdstr,status,output)
    return (status,output)
